{extend name="./base" /}

{block name="body"}
<form class="layui-form model-form" id="thisForm">
	<input name="id" type="hidden"/>
	<div class="layui-form-item">
		<label class="layui-form-label">上级规则</label>
		<div class="layui-input-block">
			<div id="authEditParentSel" class="select-tree"></div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label layui-form-required">规则名称</label>
		<div class="layui-input-block">
			<input name="form[title]" class="layui-input" lay-verify="required" value="{$data['title'] ?? ''}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">所属组件</label>
		<div class="layui-input-block">
			<input name="form[addon]" class="layui-input" value="{$data['addon'] ?? ''}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">规则URL</label>
		<div class="layui-input-block">
			<input name="form[url]" class="layui-input" value="{$data['url'] ?? ''}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">排序权重</label>
		<div class="layui-input-block">
			<input name="form[sort]" placeholder="越大越靠前" type="number" class="layui-input" value="{$data['sort'] ?? ''}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">ICON图标</label>
		<div class="layui-input-inline">
			<input name="form[icon]" placeholder="" class="layui-input" value="{$data['icon'] ?? ''}"/>
		</div>
		<div class="layui-form-mid layui-word-aux">
			<a href="https://www.layui.com/doc/element/icon.html" target="_blank" style="color:#ff0000">点此去LAYUI官网查看</a>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否白名单</label>
		<div class="layui-input-block">
			<input name="form[is_control]" type="radio" value="1" title="否"
				   {if !empty($data) && $data['is_control'] == 1 }checked{/if}/>
			<input name="form[is_control]" type="radio" value="0" title="是"
				   {if !empty($data) && $data['is_control'] == 0 }checked{/if}/>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<input type="hidden" name="form[id]" value="{$data['id'] ?? 0}">
			<button class="layui-btn" lay-filter="formSubmit" lay-submit>保存</button>
			<button class="layui-btn layui-btn-primary" type="reset" >重置</button>
		</div>
	</div>
</form>
{/block}

{block name="script"}
<script>
	layui.config({
		base: '__STATIC__/layuiadmin/lib/extend/' //静态资源所在路径
	}).use(['layer', 'form', 'table', 'xmSelect'], function () {
		var $ = layui.jquery, form= layui.form;
		var xmSelect = layui.xmSelect;

		// 表单提交
		form.on('submit(formSubmit)', function (data) {
			let formData = data.field;
			$.post('/admin/menu/edit', formData, function(res){
				layer.closeAll();
				parent.location.reload();
			})
			return false;
		});

		// 初始化树状选择器
		$.post('/admin/menu/tree', function (res) {
			var insXmSel = xmSelect.render({
				el: '#authEditParentSel',
				tips: '顶级规则',
				height: '250px',
				data: res.data,
				initValue: [{$pid}],
				model: {label: {type: 'text'}},
				prop: {
					name: 'title',
					value: 'id'
				},
				radio: true,
				clickClose: true,
				//filterable: true,
				//searchTips: '请输入关键词进行搜索',
				tree: {
					show: true,
					strict: false
				},
				disabled: false,
			});
		})


	})
</script>
{/block}